Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethinking the beep.Streamer interfaces #170

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MarkKremer
Copy link
Contributor

@MarkKremer MarkKremer commented Aug 1, 2024

  • Removed beep.StreamCloser and beep.StreamSeekCloser. These functions do not seem to add much value because the decoders that implement them only proxy the call to their source io.Reader. Besides, other beep.Streamers do not call Close() on their source streamers, so the user has to keep track of when to close the decoder or reader themselves regardless. The result of this is that all io.Reader's padded to a Decode() function must be closed manually.
  • midi.NewSoundFont() also doesn't close the supplied io.Reader anymore.

TODO

  • Test all the examples
  • Review docblocks
  • Update wiki

They don't add much value if the implementing structs are only going to proxy the Close call to the source io.Reader. Besides, other streamers don't call Close() on their source streamers, so the user needs to keep track of closing the streamer themselves anyway.
@MarkKremer MarkKremer added the future Planned for a future version of Beep label Aug 1, 2024
@MarkKremer MarkKremer force-pushed the update-streamer-interfaces branch from 822668e to 48a5d9b Compare August 1, 2024 18:45
@dusk125
Copy link
Contributor

dusk125 commented Aug 1, 2024

2 cents:
I think we should keep the interfaces, in the examples, they generally open the file, pass it to the decoder, and play it; closing the backend resource at scope end is fine if the lifetime of the frontend streamer is less than or equal to the backend resource.

However, I could see usecases where we want to pass the ReadCloser into a streamer and keep the streamer around outside of the calling scope (which in the new examples would free the underlying resource and cause a panic).

I think that keeping the StreamCloser interface is good and we could make it a bit smarter such that the decoder just takes a Reader, then checks to see if it's a *Closer when decoder.Close is called, otherwise, it's a no-op.

If that makes sense.
What do you think?

@MarkKremer
Copy link
Contributor Author

MarkKremer commented Sep 5, 2024

You make some good points. My argumentation for this interface is that Beep's composites need to be configured separately anyway. E.g. if you have a streamer, volume and ctrl node, you'll need to keep hold of them so that you can close, change volume and pause the stream. I think it's a good programming pattern to keep them in a struct to encapsulate that part of the audio business logic. So what's an extra io.ReadCloser? Removing Streamer.Close may clear up some confusion as to if both streamers and files must be closed.

I invite further opinions but I'll probably hold this PR until after I'm further with the docs and/or my music player projects so I'll have more experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future Planned for a future version of Beep
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants